<%--
  Created by IntelliJ IDEA.
  User: 骆鹏
  Date: 2017/7/27
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>申请车辆</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/css/meeting/index.css">
    <link rel="stylesheet" type="text/css" href="../../lib/fullcalendar/css/fullcalendar.css"/>
    <link rel="stylesheet" type="text/css" href="../../lib/fullcalendar/css/fullcalendar.print.css"/>
    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <style>
        .equip tbody td{
            text-align: center;
        }
        .equipSpan{
            background-color:#00a2d4;
        }
        .equip {
            width: 77%;
            margin: 20px auto;
        }
        table tbody td{
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
            padding:0 10px;
        }
        .head .headli{
            width:94px;
        }

        .pagediv{
            margin: 0 auto!important;
        }
        /*.layui-layer{*/
        /*top:200px!important;*/
        /*}*/
        .layui-layer-setwin{
            position: absolute;
            right: 15px;
            top: 15px;
            font-size: 0px;
            line-height: initial;
        }

        .fc-header-left, .fc-header-right {
            padding: 10px 18px !important;
            box-sizing: border-box;
        }

        .fc-header-left .fc-button, .fc-header-right .fc-button {
            margin-bottom: 0;
        }
    </style>
    <%--<link rel="stylesheet" href="/css/base.css">--%>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="../../lib/fullcalendar/moment.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/fullcalendar/fullcalendar.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/fullcalendar/jquery-ui.custom.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/fullcalendar/zh-cn.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/layer/layer.js?20201106" type="text/javascript" charset="utf-8"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <style>
        .typeBtn{
            float: right;
            margin: 5px 5px;
            width: 60px;
            height: 28px;
            line-height: 38px;
            color: #fff;
            border: 1px solid #ebebeb;
            outline: none;
            font-size: 14px;
            border-radius: 5px;
            line-height: 28px;
            cursor: pointer;
        }
        .M-box3 .active{
            margin: 0px 3px;
            width: 29px;
            height: 29px;
            line-height: 29px;
            background: #2b7fe0;
            font-size: 12px;
            border: 1px solid #2b7fe0;
            color:#fff;
            text-align:center;
            display: inline-block;
        }
        .M-box3 a{
            margin: 0 3px;
            width: 29px;
            height: 29px;
            line-height: 29px;
            font-size: 12px;
            display: inline-block;
            text-align:center;
            background: #fff;
            border: 1px solid #ebebeb;
            color: #bdbdbd;
            text-decoration: none;
        }
        .jump-ipt{
            float: left;
            width: 30px;
            height: 30px;
        }
        .layui-layer{
            top:0px!important;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
</head>
<body style="font-family: 微软雅黑;">

<div class="head w clearfix">
    <div class="colorClass" style="margin-right: 20px;">
        <a href="javascript:;" style="background-color: rgb(58, 135, 173);"></a>
        <span><fmt:message code="meet.th.PendingApproval" /></span>
        <a href="javascript:;" style="background-color: rgb(105, 240, 164);"></a>
        <span><fmt:message code="meet.th.Ratified" /></span>
        <%--<a href="javascript:;" style="background-color: rgb(255, 136, 124);"></a>
        <span><fmt:message code="meet.th.HaveHand" /></span>--%>
        <a href="javascript:;" style="background-color: rgb(245, 181, 46);"></a>
        <span><fmt:message code="meet.th.unratified" /></span>
        <%--<a href="javascript:;" style="background-color: rgb(219, 173, 255);"></a>
        <span style="margin-right: 24px"><fmt:message code="meet.th.IsOver" /></span>--%>
    </div>

</div>
<div class="meentingDate" style="display: block;padding: 0 18px 20px;">
    <%--<input class="typeBtn" type="button" onclick="addMeeting()" value="申请" style="background: dodgerblue"/>--%>
    <div class="mainList">
    </div>
</div>
<div class="pagediv" id="already" style="margin: 0 auto;width: 97%;display: none;margin-top: 10px;">
    <div class="headTop" style="z-index: 999;">
        <div class="headImg">
            <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_apply.png" alt="">
        </div>
        <div class="divTitle">
            申请车辆
        </div>
    </div>
    <table>
        <thead>
        <%--<tr>
            <th width="11%" style="text-align:center"><fmt:message code="meet.th.ConferenceName" /></th>
            <th width="11%" style="text-align:center"><fmt:message code="meet.th.ConferenceTitle" /></th>
            <th width="15%" style="text-align:center"><fmt:message code="sup.th.ApplicationTime" /></th>
            <th width="15%" style="text-align:center"><fmt:message code="sup.th.startTime" /></th>
            <th width="15%" style="text-align:center"><fmt:message code="meet.th.EndTime" /></th>
            <th width="9%" style="text-align:center"><fmt:message code="meet.th.ConferenceRoom" /></th>
            <th width="9%" style="text-align:center"><fmt:message code="sup.th.Applicant" /></th>
            <th width="15%" style="text-align:center"><fmt:message code="notice.th.operation" /></th>
        </tr>--%>
        </thead>
        <tbody>

        </tbody>

    </table>
    <div id="dbgz_page" class="M-box3 fr" style="margin-right: 5%;margin-top: 1%">

    </div>
</div>

<script>
    var editFlag=${editFlag};
    var sign=${sign};
    var user_id="";
    var dept_id="";
    /* var date = new Date();*/
    /* var start = {
         format: 'YYYY-MM-DD hh:mm:ss',
         /!* min: laydate.now(), //设定最小日期为当前日期*!/
         /!* max: '2099-06-16 23:59:59', //最大日期*!/
         /!*min:date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate(),*!/
         istime: true,
         istoday: false,
         choose: function(datas){
             end.min = datas; //开始日选好后，重置结束日的最小日期
             end.start = datas //将结束日的初始值设定为开始日
         }
     };
     var end = {
         format: 'YYYY-MM-DD hh:mm:ss',
         istime: true,
         istoday: false,
         choose: function(datas){
             start.max = datas; //结束日选好后，重置开始日的最大日期
         }
     };*/
    //时间控件调用
    /*   var start = {
           format: 'hh:mm',
           /!* min: laydate.now(), //设定最小日期为当前日期*!/
           /!* max: '2099-06-16 23:59:59', //最大日期*!/
           istime: true,
           istoday: false,
           choose: function(datas){
               end.min = datas; //开始日选好后，重置结束日的最小日期
               end.start = datas //将结束日的初始值设定为开始日
           }
       };
       var end = {
           format: 'hh:mm',
           /!*min: laydate.now(),*!/
           /!*max: '2099-06-16 23:59:59',*!/
           istime: true,
           istoday: false,
           choose: function(datas){
               start.max = datas; //结束日选好后，重置开始日的最大日期
           }
       };*/
    // 查询提醒权限
    $.ajax({
        type:'get',
        url:'/smsRemind/getRemindFlag',
        dataType:'json',
        data:{
            type:9
        },
        success:function (res) {
            if(res.flag){
                if(res.obj.length>0){
                    var data = res.obj[0];
                    // 是否默认发送
                    if(data.smsRemind=='0'){
                        $('.smsRemind').prop("checked", false);
                    }else if(data.smsRemind=='1'){
                        $('.smsRemind').prop("checked", true);
                    }
                    // 是否手机短信默认提醒
                    if(data.sms2Remind=='0'){
                        $('.sms2Remind').prop("checked", false);
                    } else if (data.sms2Remind=='1'){
                        $('.sms2Remind').prop("checked", true);
                    }
                    // 是否允许发送事务提醒
                    if(data.isCan=='0'){
                        $('.sms2Remind').prop("checked", false);
                        $('.smsRemind').prop("checked", false);
                        $('.items').hide();
                    }

                }
            }
        }
    })

    var start = {
        elem: '#vuStart',
        format: 'YYYY-MM-DD hh:mm:ss',
        /* min: laydate.now(), //设定最小日期为当前日期
         max: '2099-06-16 23:59:59', //最大日期*/
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas; //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#vuEnd',
        format: 'YYYY-MM-DD hh:mm:ss',
        /*     min: laydate.now(),
         max: '2099-06-16 23:59:59',*/
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    $('.mainList').fullCalendar({
        header: {
            left: 'prev,next,today',
            center: 'title',
            right: 'month,agendaWeek'
        },
        buttonText: {
            today: '<fmt:message code="meet.th.JumpthDay" />'
        },
        lang: 'zh-cn',
        editable: true,
        events: function (start, end, timezone, callback) {
            var date = this.getDate().format('YYYY-MM');
            $.ajax({
                url: '<%=basePath %>veHicleUsage/selectAllObjects',
                dataType: 'json',
                data: {
                    date:date
                },
                success: function (res) { // 获取当前月的数据
                    var datas = res.obj;
                    var events = [];
                    var TColor = '';
                    var BColor = '';
                    for (var i = 0; i < datas.length; i++) {

                        if (datas[i].vuStatus == '0') {
                            BColor = 'rgb(58, 135, 173)';
                        } else if (datas[i].vuStatus == '1') {
                            BColor = 'rgb(105, 240, 164)';
                        } else if (datas[i].vuStatus == '2') {
                            BColor = 'rgb(245, 181, 46)';
                        }
                        events.push({
                            id: datas[i].vuId,
                            title:datas[i].vuStart.split(' ')[1]+"  "+datas[i].vuUserName,
                            start: datas[i].vuStart, // vuRequestDate will be parsed
                            textColor: '#fff',
                            backgroundColor: BColor
                        });
                    }
                    callback(events);
                }
            });
        },
        //新增功能
        dayClick: function (date, allDay, jsEvent, view) {
            var timestamp = Date.parse(new Date());
            var timer = parseInt(timestamp) + 7200000;
            var startTime = new Date(timestamp).Format('hh:mm:ss');
            var endTime = new Date(timer).Format('hh:mm:ss');
            layer.open({
                type: 1,
                title: ['申请车辆', 'background-color:#2b7fe0;color:#fff;'],
                area: ['800px', '500px'],
                offset: 'auto',
                shadeClose: true, //点击遮罩关闭
                btn: ['保存', '关闭'],
                content: '<div class="div_table" style="">' +
                    '<div class="div_tr">' +
                    '<span class="span_td">车牌号：</span>' +
                    '<select name="vId" id="vId" style="width: 42%;" class="BigSelect">' +
                    '</select><span style="color: red;">&nbsp;*&nbsp;&nbsp;<fmt:message  code="event.th.(required)"/></span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">用车人：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%">' +
                    '<textarea  id="vuUser" cols="" rows="3" disabled style="width:85%; resize: none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="addvuUser"><fmt:message  code="global.lang.select"/></a></span>' +
                    '<span class="add_img" style="margin-left: 10px"> <a href="javascript:void(0);"  id="addvuUsers"><fmt:message  code="global.lang.empty"/></a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">司机：</span>' +
                    '<select name="vDriverName" id="vDriverName" style="width:42%;">' +
                    <%--"<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>"+--%>
                    '</select><span style="color: red;">&nbsp;*&nbsp;&nbsp;<fmt:message  code="event.th.(required)"/></span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">用车部门：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%;">' +
                    '<textarea  id="vuDept" cols="" rows="3" disabled style="width: 85%; resize:none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="addvuDept"><fmt:message  code="global.lang.select"/></a></span>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:void(0);" id="addvuDepts"><fmt:message  code="global.lang.empty"/></a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">跟随人员：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%;">' +
                    '<textarea  id="vuSuite" cols="" rows="3" disabled style="width: 85%; resize: none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="addvuSuite">选择</a></span>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="clearvuSuite">清空</a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">起始时间：</span>' +
                    '<span style="margin:0 5px;">从</span><span><input type="text" name="vuStart" value="'+date._i+' '+startTime+'" id="vuStart" style="height: 28px;width: 150px;" value="" onclick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\',max: $(\'#vuEnd\').val()})"></span>' +
                    '<span style="margin:0 5px;"><fmt:message code="global.lang.to" /></span>' +
                    '<span><input type="text" name="vuEnd" id="vuEnd" style="height: 28px;width: 150px;" value="'+date._i+' '+endTime+'" onclick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\',min: $(\'#vuStart\').val()})"></span>' +
                    '<span style="color: #FF0000;margin-left: 10px;font-size: 16px;">*</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">目的地：</span>' +
                    '<span><input type="text" name="vuDestination" style="height: 28px; width: 70%;margin-left: 5px;" id="vuDestination" value=""></span>' +
                    '<span style="color: #FF0000;margin-left: 10px;font-size: 16px;">*</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">申请里程：</span>' +
                    '<span><input type="text" name="vuMileage" style="height: 28px;width: 70%;margin-left: 5px;" value="" id="vuMileage" oninput="value=value.replace(/[^\\d]/g,\'\')" ><fmt:message  code="event.th.(kilometer)"/></span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">部门审批人：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%">' +
                    '<textarea id="deptManager" cols="" rows="3" style="width: 85%;resize: none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"> <a href="javascript:;" id="adddeptManager"><fmt:message  code="global.lang.select"/></a></span>' +
                    '<span class="add_img" style="margin-left: 10px"> <a href="javascript:void(0);" id="adddeptManagers"><fmt:message  code="global.lang.empty"/></a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">调度员：</span>' +
                    '<select name="vuOperator" style="width: 42%" id="vuOperator">' +
                    '</select><span style="color: red;">&nbsp;*</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">事由：</span><span><div class="inPole" style="width: 70%">' +
                    '<textarea name="vuReason" id="vuReason" cols="" rows="3" style="width: 85%;resize: vertical;"></textarea>' +
                    '</div></span></div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">备注：</span><span><div class="inPole" style="width: 70%">' +
                    '<textarea name="vuRemark" id="vuRemark" cols="" rows="3" style="width: 85%;resize: vertical;"></textarea>' +
                    '</div></span>' +
                    '<span class="span_td">提醒内容：</span><span><div class="inPole" style="width: 70%;margin-top:10px">' +
                    '<textarea name="remindContent" id="remindContent" cols="" rows="3" style="width: 85%;resize: vertical;"></textarea>' +
                    '</div></span>' +
                    '<div class="control-group items"><span class="span_td tixing" style="margin-left:10px;margin-right:10px">事务提醒:</span><span><input type="checkbox" class="smsRemind" checked="checked" style="width:16px;vertical-align: middle;">部门审批人&nbsp;&nbsp;<input type="checkbox" class="sms2Remind" style="width:16px;vertical-align: middle;">调度人员提醒</span></span></div>\n'+
                    '</div>' +
                    '</div>',
                yes: function (index) {

                    //点击保存按钮
                    if (editFlag == 0) {
                        /*  if ($('#vId').val() == "") {
                         $.layerMsg({content: "请选择车牌号", icon: 2});
                         } else {*/
                        if ($('#vId').val() == ""){
                            $.layerMsg({content: "<fmt:message  code="event.th.number"/>", icon: 2});
                            return false;
                        }
                        if ($('#vDriverName').val() == ""){
                            $.layerMsg({content: "请选择司机", icon: 2});
                            return false;
                        }
                        if($('#vuStart').val()==""||$('#vuEnd').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Vehicleverification"/>", icon: 2});
                            return false;
                        }
                        if($('#vuDestination').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Destination"/>", icon: 2});
                            return false;
                        }
                        if($('#vuOperator').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.FillDispatcher"/>", icon: 2});
                            return false;
                        }else{
                            $.ajax({
                                url: "/veHicleUsage/addVeHicle",
                                type: 'post',
                                dataType: 'json',
                                data: {
                                    vId:$("#vId").val(),
                                    vuDriver:$("#vDriverName").val(),
                                    vuStart:$("#vuStart").val(),
                                    vuEnd:$("#vuEnd").val(),
                                    vuDestination:$("#vuDestination").val(),
                                    vuOperator:$("#vuOperator").val(),
                                    vuReason:$("#vuReason").val(),
                                    vuRemark:$("#vuRemark").val(),
                                    remindContent:$('#remindContent').val(),
                                    vuMileage:$("#vuMileage").val(),
                                    vuDept: $("#vuDept").attr("deptid"),//用车部门
                                    vuUser: $("#vuUser").attr("user_id").substr(0,$("#vuUser").attr("user_id").length-1),//用车人
                                    vuSuite: $("#vuSuite").attr("user_id"),//随行人员
                                    deptManager: $("#deptManager").attr("user_id"),//部门审批人
                                    vuMileage:$('#vuMileage').val(),
                                    smsRemind:function(){
                                        if($('.smsRemind').prop('checked')==false){
                                            return '0';
                                        }else {
                                            return '1';
                                        }
                                    },
                                    sms2Remind:function(){
                                        if($('.sms2Remind').prop('checked')==false){
                                            return '0';
                                        }else {
                                            return '1';
                                        }
                                    }
                                }
                                , success: function (json) {
                                    if (json.flag) {
                                        $.layerMsg({content: '<fmt:message  code="url.th.addSuccess"/>！', icon: 1}, function () {
                                            window.location.href = '<%=basePath%>/veHicle/pendingApply';
                                        });
                                    } else {
                                        $.layerMsg({content: json.msg + '！', icon: 1}, function () {
                                        });
                                    }
                                }
                            })
                        }
                    }else{
                        $('#editVehicleUseForm').ajaxSubmit({
                            url: "/veHicleUsage/editVehicleUsage",
                            type: 'post',
                            dataType: 'json',
                            data: {
                                vuId:$('#vuId').val(),
                                vuDriver:$('#vDriverName').val(),
                                vuDept: $("#vuDept").attr("deptid"),//用车部门
                                vuUser: $("#vuUser").attr("user_id"),//用车人
                                vuSuite: $("#vuSuite").attr("user_id"),//随行人员
                                deptManager: $("#deptManager").attr("user_id"),//部门审批人
                            }, success: function (json) {
                                if(json.flag) {
                                    $.layerMsg({content: '<fmt:message  code="depatement.th.Modifysuccessfully"/>！', icon: 1}, function () {
                                        if(sign==1){
                                            window.location.href='<%=basePath%>/veHicle/operatorpendingApply';
                                        }else if(sign==2){
                                            window.location.href='<%=basePath%>/veHicle/operatorapprovedApply';
                                        }
                                        else if(sign==3){
                                            window.location.href='<%=basePath%>/veHicle/operatorinUseVehicle';
                                        }
                                        else if(sign==4){
                                            window.location.href='<%=basePath%>/veHicle/operatornotApply';
                                        }else if(sign==5){
                                            window.location.href='<%=basePath%>/veHicle/operatorUseEnd';
                                        }


                                    });
                                }else{
                                    $.layerMsg({content: json.msg+'！', icon: 1}, function () {
                                    });
                                }
                            }
                        })
                    }
                },
                success:function(){
                    $('#vuUser').attr('user_id',$.cookie("userId")+',');
                    $('#vuUser').attr('dataid',$.cookie("uid")+',');
                    $('#vuUser').val($.cookie("userName")+',');


                    //用车人
                    $('#addvuUser').click(function(){
                        user_id="vuUser";
                        $.popWindow("../../common/selectUser?0");
                    });
                    // 用车人清空
                    $('#addvuUsers').click(function(){
                        $("#vuUser").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':''
                        });
                    });
                    //部门审批人
                    $('#adddeptManager').click(function(){
                        user_id="deptManager";
                        $.popWindow("../../common/selectUser?0");
                    });
                    // 部门审批人清空
                    $('#adddeptManagers').click(function(){
                        $("#deptManager").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':''
                        });
                    });
                    //用车部门
                    $('#addvuDept').click(function(){
                        dept_id="vuDept";
                        $.popWindow("../../common/selectDept?0");
                    });
                    // 用车部门清空
                    $('#addvuDepts').click(function(){
                        $("#vuDept").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':'',
                            'deptname':'',
                            'deptid':'',

                        });
                    });
                    //随行人员
                    $('#addvuSuite').click(function(){
                        user_id="vuSuite";
                        $.popWindow("../../common/selectUser");
                    });
                    // 随行人员清空
                    $('#clearvuSuite').click(function(){
                        $("#vuSuite").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':''
                        });
                    });
                    function clicks(id){
                        if(id == 'vuUser'||id == 'deptManager'){
                            $('#'+id).val('').attr({
                                'dataid':'',
                                'user_id':'',
                                'username':'',
                                'userprivname':''
                            })
                        }else if(id == 'vuDept'){
                            $('#'+id).val('').attr({
                                'deptid':''
                            })
                        }

                    }
                    function initManager(){
                        $.ajax({
                            url: '/syspara/getOperator',
                            type: 'get',
                            dataType: 'json',
                            data: {
                                paraName:"OPERATOR_NAME"
                            },
                            success: function (obj) {
                                var data=obj.object;
                                var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                                if(data!=null){
                                    for(var i=0;i<data.eduUserList.length;i++){
                                        str+='<option value="'+data.eduUserList[i].userId+'">'+data.eduUserList[i].userName+'</option>';
                                    }
                                }
                                var managerNameArray=data.userName.split(",");
                                $("#vuOperator").html(str);
                            }
                        });
                    }

                    $(function(){
                        //下拉框获取
                        $.ajax({
                            type:'post',
                            url:'<%=basePath%>veHicle/getDropDownBox',
                            dataType:'json',
                            success:function(result){
                                var data =result.obj;
                                var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                                if(data.length>0){
                                    for(var i=0;i<data.length;i++){
                                        str=str+ '<option value="' + data[i].vId + '">' + data[i].vNum + '</option>'
                                    }
                                }
                                $('#vId').html(str);
                            }
                        })
                        $('#vId').on('change',function () {
                            // console.log($(this).find('option:selected').val())
                            $.ajax({
                                url: '/veHicle/getDetailVeHicle',
                                type: 'get',
                                data: {
                                    vId: $(this).find('option:selected').val()
                                },
                                dataType: 'json',
                                success: function (res) {
                                    var vDriver=res.obj.vDriver.substr(0,res.obj.vDriver.length-1).split(',')
                                    var vDriverName=res.obj.vDriverName.substr(0,res.obj.vDriverName.length-1).split(',')
                                    var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                                    for(var i=0;i<vDriverName.length;i++){
                                        str=str+ '<option value="'+vDriver[i]+'">' + vDriverName[i] + '</option>'
                                    }
                                    $('#vDriverName').html(str);

                                }
                            })
                        })
                        initManager()
                    })


                    function check(){
                        if ($('#vId').val() == ""){
                            $.layerMsg({content: "<fmt:message  code="event.th.number"/>", icon: 2});
                            return false;
                        }
                        if($('#vuStart').val()==""||$('#vuEnd').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Vehicleverification"/>", icon: 2});
                            return false;
                        }
                        if($('#vuDestination').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Destination"/>", icon: 2});
                            return false;
                        }
                        if($('#vuOperator').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.FillDispatcher"/>", icon: 2});
                            return false;
                        }else{
                            return true;
                        }

                    }
                    //点击清空按钮
                    $('.reset_btn').click(function () {
                        $('#vId').val("");
                        $("#vuDept").attr("deptid","");
                        $("#vuDept").val("");
                        $("#vuUser").attr("user_id","");
                        $("#vuUser").val("");
                        $("#vuSuite").attr("user_id","");
                        $("#vuSuite").val("");
                        $("#deptManager").attr("user_id","");
                        $("#deptManager").val("");
                        $("#vuOperator").val("");
                        $("#vuStart").val("");
                        $("#vuEnd").val("");
                        $("#vuDestination").val("");
                        $("#vuMileage").val("");
                        $("#vuReason").val("");
                        $("#vuRemark").val("");
                        $('#remindContent').val("")
                    })

                }
            });
        },
        //编辑查看
        eventClick:function (calEvent,date,jsEvent, view) {
            var vuId = calEvent.id
            var timestamp = Date.parse(new Date());
            var timer = parseInt(timestamp) + 7200000;
            layer.open({
                type: 1,
                title: ['申请车辆', 'background-color:#2b7fe0;color:#fff;'],
                area: ['800px', '500px'],
                offset: 'auto',
                shadeClose: true, //点击遮罩关闭
                btn: ['保存', '关闭'],
                content: '<div class="div_table" style="">' +
                    '<div class="div_tr">' +
                    '<span class="span_td">车牌号：</span>' +
                    '<select name="vId" id="vId" style="width: 42%;" class="BigSelects">' +
                    '</select><span style="color: red;">&nbsp;*&nbsp;&nbsp;<fmt:message  code="event.th.(required)"/></span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">用车人：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%">' +
                    '<textarea  id="vuUser" cols="" rows="3" user_id="" disabled style="width:85%; resize: none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="addvuUser"><fmt:message  code="global.lang.select"/></a></span>' +
                    '<span class="add_img" style="margin-left: 10px"> <a href="javascript:void(0);"  id="addvuUsers"><fmt:message  code="global.lang.empty"/></a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">司机：</span>' +
                    '<select name="vDriverName" id="vDriver" style="width:42%;">' +
                    <%--"<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>"+--%>
                    '</select><span style="color: red;">&nbsp;*&nbsp;&nbsp;<fmt:message  code="event.th.(required)"/></span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">用车部门：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%;">' +
                    '<textarea  id="vuDept" cols="" rows="3" deptid="" disabled style="width: 85%; resize:none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="addvuDept"><fmt:message  code="global.lang.select"/></a></span>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:void(0);" id="addvuDepts"><fmt:message  code="global.lang.empty"/></a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">跟随人员：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%;">' +
                    '<textarea  id="vuSuite" cols="" rows="3" user_id="" disabled style="width: 85%; resize: none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="addvuSuite">选择</a></span>' +
                    '<span class="add_img" style="margin-left: 10px"><a href="javascript:;" id="clearvuSuite">清空</a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">起始时间：</span>' +
                    '<span style="margin:0 5px;">从</span><span><input type="text" name="vuStart" id="vuStart" style="height: 28px;width: 150px;" value="" onclick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\',max: $(\'#vuEnd\').val()})"></span>' +
                    '<span style="margin:0 5px;"><fmt:message code="global.lang.to" /></span>' +
                    '<span><input type="text" name="vuEnd" id="vuEnd" style="height: 28px;width: 150px;"  onclick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\',min: $(\'#vuEnd\').val()})"></span>' +
                    '<span style="color: #FF0000;margin-left: 10px;font-size: 16px;">*</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">目的地：</span>' +
                    '<span><input type="text" name="vuDestination" style="height: 28px; width: 70%;margin-left: 5px;" id="vuDestination" ></span>' +
                    '<span style="color: #FF0000;margin-left: 10px;font-size: 16px;">*</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">申请里程：</span>' +
                    '<span><input type="text" name="vuMileage" style="height: 28px;width: 70%;margin-left: 5px;"  id="vuMileage" oninput="value=value.replace(/[^\\d]/g,\'\')" ><fmt:message  code="event.th.(kilometer)"/></span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">部门审批人：</span>' +
                    '<span>' +
                    '<div class="inPole" style="width: 70%">' +
                    '<textarea id="deptManager" cols="" rows="3"  style="width: 85%;resize: none;"></textarea>' +
                    '<span class="add_img" style="margin-left: 10px"> <a href="javascript:;" id="adddeptManager"><fmt:message  code="global.lang.select"/></a></span>' +
                    '<span class="add_img" style="margin-left: 10px"> <a href="javascript:void(0);" id="adddeptManagers"><fmt:message  code="global.lang.empty"/></a></span>' +
                    '</div>' +
                    '</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">调度员：</span>' +
                    '<select name="vuOperator" style="width: 42%" id="Operator">' +
                    '</select><span style="color: red;">&nbsp;*</span>' +
                    '</div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">事由：</span><span><div class="inPole" style="width: 70%">' +
                    '<textarea name="vuReason" id="vuReason" cols="" rows="3" style="width: 85%;resize: vertical;"></textarea>' +
                    '</div></span></div>' +
                    '<div class="div_tr">' +
                    '<span class="span_td">备注：</span><span><div class="inPole" style="width: 70%">' +
                    '<textarea name="vuRemark" id="vuRemark" cols="" rows="3" style="width: 85%;resize: vertical;"></textarea>' +
                    '</div></span>' +
                    '<span class="span_td">提醒内容：</span><span><div class="inPole" style="width: 70%;margin-top:10px">' +
                    '<textarea name="remindContent" id="remindContent" cols="" rows="3" style="width: 85%;resize: vertical;"></textarea>' +
                    '</div></span>' +
                    '<div class="control-group items"><span class="span_td tixing" style="margin-left:10px;margin-right:10px">事务提醒:</span><span><input type="checkbox" class="smsRemind" checked="checked" style="width:16px;vertical-align: middle;">部门审批人&nbsp;&nbsp;<input type="checkbox" class="sms2Remind" style="width:16px;vertical-align: middle;">调度人员提醒</span></span></div>\n'+
                    '</div>' +
                    '</div>',
                success:function(){

                    //下拉框获取
                    $.ajax({
                        type:'post',
                        url:'<%=basePath%>veHicle/getDropDownBox',
                        dataType:'json',
                        success:function(result){
                            var data1 =result.obj;
                            var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                            if(data1.length>0){
                                for(var i=0;i<data1.length;i++){
                                    str=str+ '<option value="' + data1[i].vId + '">' + data1[i].vNum + '</option>'
                                }
                            }
                            $('.BigSelects').html(str);
                        }
                    })
                    $('.BigSelects').on('change',function () {
                        $.ajax({
                            url: '/veHicle/getDetailVeHicle',
                            type: 'get',
                            data: {
                                vId: $(this).find('option:selected').val()
                            },
                            dataType: 'json',
                            success: function (res) {
                                var vDriver=res.obj.vDriver.substr(0,res.obj.vDriver.length-1).split(',')
                                var vDriverName=res.obj.vDriverName.substr(0,res.obj.vDriverName.length-1).split(',')
                                var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                                for(var i=0;i<vDriverName.length;i++){
                                    str=str+ '<option value="'+vDriver[i]+'">' + vDriverName[i] + '</option>'
                                }
                                $('#vDriver').html(str);

                            }
                        })
                    })
                    initManager()
                    $('#vuUser').attr('user_id',$.cookie("userId")+',');
                    $('#vuUser').attr('dataid',$.cookie("uid")+',');
                    $('#vuUser').val($.cookie("userName")+',');


                    //用车人
                    $('#addvuUser').click(function(){
                        user_id="vuUser";
                        $.popWindow("../../common/selectUser?0");
                    });
                    // 用车人清空
                    $('#addvuUsers').click(function(){
                        $("#vuUser").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':''
                        });
                    });
                    //部门审批人
                    $('#adddeptManager').click(function(){
                        user_id="deptManager";
                        $.popWindow("../../common/selectUser?0");
                    });
                    // 部门审批人清空
                    $('#adddeptManagers').click(function(){
                        $("#deptManager").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':''
                        });
                    });
                    //用车部门
                    $('#addvuDept').click(function(){
                        dept_id="vuDept";
                        $.popWindow("../../common/selectDept?0");
                    });
                    // 用车部门清空
                    $('#addvuDepts').click(function(){
                        $("#vuDept").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':'',
                            'deptname':'',
                            'deptid':'',

                        });
                    });
                    //随行人员
                    $('#addvuSuite').click(function(){
                        user_id="vuSuite";
                        $.popWindow("../../common/selectUser");
                    });
                    // 随行人员清空
                    $('#clearvuSuite').click(function(){
                        $("#vuSuite").val("").attr({
                            'username':'',
                            'dataid':'',
                            'user_id':'',
                            'userprivname':''
                        });
                    });
                    function clicks(id){
                        if(id == 'vuUser'||id == 'deptManager'){
                            $('#'+id).val('').attr({
                                'dataid':'',
                                'user_id':'',
                                'username':'',
                                'userprivname':''
                            })
                        }else if(id == 'vuDept'){
                            $('#'+id).val('').attr({
                                'deptid':''
                            })
                        }

                    }
                    function initManager(){
                        $.ajax({
                            url: '/syspara/getOperator',
                            type: 'get',
                            dataType: 'json',
                            data: {
                                paraName:"OPERATOR_NAME"
                            },
                            success: function (obj) {
                                var data=obj.object;
                                var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                                if(data!=null){
                                    for(var i=0;i<data.eduUserList.length;i++){
                                        str+='<option value="'+data.eduUserList[i].userId+'">'+data.eduUserList[i].userName+'</option>';
                                    }
                                }
                                var managerNameArray=data.userName.split(",");
                                $("#Operator").html(str);
                            }
                        });
                    }
                    function check(){
                        if ($('#vId').val() == ""){
                            $.layerMsg({content: "<fmt:message  code="event.th.number"/>", icon: 2});
                            return false;
                        }
                        if($('#vuStart').val()==""||$('#vuEnd').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Vehicleverification"/>", icon: 2});
                            return false;
                        }
                        if($('#vuDestination').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Destination"/>", icon: 2});
                            return false;
                        }
                        if($('#Operator').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.FillDispatcher"/>", icon: 2});
                            return false;
                        }else{
                            return true;
                        }

                    }
                    //点击清空按钮
                    $('.reset_btn').click(function () {
                        $('#vId').val("");
                        $("#vuDept").attr("deptid","");
                        $("#vuDept").val("");
                        $("#vuUser").attr("user_id","");
                        $("#vuUser").val("");
                        $("#vuSuite").attr("user_id","");
                        $("#vuSuite").val("");
                        $("#deptManager").attr("user_id","");
                        $("#deptManager").val("");
                        $("#Operator").val("");
                        $("#vuStart").val("");
                        $("#vuEnd").val("");
                        $("#vuDestination").val("");
                        $("#vuMileage").val("");
                        $("#vuReason").val("");
                        $("#vuRemark").val("");
                        $('#remindContent').val("")
                    })
                    //回显
                    $.ajax({
                        url:'/veHicleUsage/getVehicleUsageDetail',
                        dataType: 'json',
                        data: {
                            vuId: vuId
                        },
                        success:function (res) {
                            var data = res.obj;
                            $('#vuUser').attr('user_id',data.vuUser);
                            $('#vuUser').val(data.vuUserName);
                            $('#vuDept').attr('deptid',data.vuDept);
                            $('#vuDept').val(data.vuDeptName);
                            $('#vuSuite').attr('user_id',data.vuSuite);
                            $('#vuSuite').val(data.vuSuiteName);
                            $('#vuStart').val(data.vuStart);
                            $('#vuEnd').val(data.vuEnd);
                            $('#vuDestination').val(data.vuDestination);
                            $('#vuMileage').val(data.vuMileage);
                            $('#deptManager').attr('user_id',data.deptManager);
                            $('#deptManager').val(data.deptManagerName)
                            $('#vuReason').val(data.vuReason);
                            $('#vuRemark').val(data.vuRemark);
                            $('#remindContent').val(data.remindContent)
                            $('.BigSelects').val(data.vId);
                            $('#Operator').val(data.vuOperator)
                            $.ajax({
                                url: '/veHicle/getDetailVeHicle',
                                type: 'get',
                                data: {
                                    vId: $('.BigSelects').val()
                                },
                                dataType: 'json',
                                success: function (res) {
                                    var vDriver=res.obj.vDriver.substr(0,res.obj.vDriver.length-1).split(',')
                                    var vDriverName=res.obj.vDriverName.substr(0,res.obj.vDriverName.length-1).split(',')
                                    var str="<option value=''><fmt:message  code="hr.th.PleaseSelect"/></option>";
                                    for(var i=0;i<vDriverName.length;i++){
                                        str=str+ '<option value="'+vDriver[i]+'">' + vDriverName[i] + '</option>'
                                    }
                                    $('#vDriver').html(str);
                                    $('#vDriver').val(data.vuDriver)
                                }
                            })

                            // 是否默认发送
                            if(data.smsRemind=='0'){
                                $('.smsRemind').prop("checked", false);
                            }else if(data.smsRemind=='1'){
                                $('.smsRemind').prop("checked", true);
                            }
                            // 是否手机短信默认提醒
                            if(data.sms2Remind=='0'){
                                $('.sms2Remind').prop("checked", false);
                            } else if (data.sms2Remind=='1'){
                                $('.sms2Remind').prop("checked", true);
                            }

                        }
                    });

                },
                yes: function (index) {
                    //点击保存按钮
                    if (editFlag == 0) {
                        if ($('#vId').val() == ""){
                            $.layerMsg({content: "<fmt:message  code="event.th.number"/>", icon: 2});
                            return false;
                        }
                        if ($('#vDriverName').val() == ""){
                            $.layerMsg({content: "请选择司机", icon: 2});
                            return false;
                        }
                        if($('#vuStart').val()==""||$('#vuEnd').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Vehicleverification"/>", icon: 2});
                            return false;
                        }
                        if($('#vuDestination').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.Destination"/>", icon: 2});
                            return false;
                        }
                        if($('#Operator').val()==""){
                            $.layerMsg({content: "<fmt:message  code="event.th.FillDispatcher"/>", icon: 2});
                            return false;
                        }else{
                            $.ajax({
                                url: "/veHicleUsage/editVehicleUsage",
                                type: 'post',
                                dataType: 'json',
                                data: {
                                    vId:$("#vId").val(),
                                    vuDriver:$("#vDriverName").val(),
                                    vuStart:$("#vuStart").val(),
                                    vuEnd:$("#vuEnd").val(),
                                    vuDestination:$("#vuDestination").val(),
                                    vuOperator:$("#Operator").val(),
                                    vuReason:$("#vuReason").val(),
                                    vuRemark:$("#vuRemark").val(),
                                    vuMileage:$("#vuMileage").val(),
                                    vuDept: $("#vuDept").attr("deptid"),//用车部门
                                    vuUser: $("#vuUser").attr("user_id").substr(0,$("#vuUser").attr("user_id").length-1),//用车人
                                    vuSuite: $("#vuSuite").attr("user_id"),//随行人员
                                    deptManager: $("#deptManager").attr("user_id"),//部门审批人
                                    vuMileage:$('#vuMileage').val(),
                                    vuId:vuId,
                                    smsRemind:function(){
                                        if($('.smsRemind').prop('checked')==false){
                                            return '0';
                                        }else {
                                            return '1';
                                        }
                                    },
                                    sms2Remind:function(){
                                        if($('.sms2Remind').prop('checked')==false){
                                            return '0';
                                        }else {
                                            return '1';
                                        }
                                    }
                                }, success: function (json) {
                                    if (json.flag) {
                                        $.layerMsg({content: '修改成功！', icon: 1}, function () {
                                            window.location.href = '<%=basePath%>/veHicle/pendingApply';
                                        });
                                    } else {
                                        $.layerMsg({content: json.msg + '！', icon: 1}, function () {
                                        });
                                    }
                                }
                            })
                        }
                    }
                }
            })


        }
    })
    //判断是否为空
    function esName(name){
        if (name!=undefined){
            return name;
        }
        return '';
    }




</script>
</body>
</html>
